/*
 * RSInstance.cpp
 *
 *  Created on: 2010/03/13
 *      Author: alexandre
 */

#include "RSInstance.h"

namespace Realsphere {

    RSInstance::RSInstance ( RSInstanceType rInstanceType, const QString& rUrl, const QString& rName, const QString& rScopeId ) :
        RSElement ( RSInstance::InstanceTypeToTag ( rInstanceType ) )
    {
        mInstanceType = rInstanceType;
        SetName ( rName, false );
        SetScopeId ( rScopeId, false );
        SetUrl ( rUrl, false );
    }

    RSInstance::~RSInstance ()
    {
    }

    QString RSInstance::ScopeId () const
    {
        return mScopeId;
    }

    QString RSInstance::Url () const
    {
        return mUrl;
    }

    RSInstanceType RSInstance::InstanceType () const
    {
        return mInstanceType;
    }

    void RSInstance::SetScopeId ( const QString& rScopeId, bool rEmit )
    {
        mScopeId = rScopeId;
        if ( rEmit )
            emit ScopeIdChanged ( mScopeId );
    }

    void RSInstance::SetUrl ( const QString& rUrl, bool rEmit )
    {
        mUrl = rUrl;
        if ( rEmit )
            emit UrlChanged ( mUrl );
    }

    QString RSInstance::InstanceTypeToTag ( RSInstanceType rInstanceType )
    {

        switch ( rInstanceType )
        {
            case RS_ANIMATION_INSTANCE:
                return QString ( RS_ANIMATION_INSTANCE_TAG );
                break;
            case RS_CAMERA_INSTANCE:
                return QString ( RS_CAMERA_INSTANCE_TAG );
                break;
            case RS_CONTROLLER_INSTANCE:
                return QString ( RS_CONTROLLER_INSTANCE_TAG );
                break;
            case RS_FORMULA_INSTANCE:
                return QString ( RS_FORMULA_INSTANCE_TAG );
                break;
            case RS_GEOMETRY_INSTANCE:
                return QString ( RS_GEOMETRY_INSTANCE_TAG );
                break;
            case RS_LIGHT_INSTANCE:
                return QString ( RS_LIGHT_INSTANCE_TAG );
                break;
            case RS_NODE_INSTANCE:
                return QString ( RS_NODE_INSTANCE_TAG );
                break;
            case RS_VISUAL_SCENE_INSTANCE:
                return QString ( RS_VISUAL_SCENE_INSTANCE_TAG );
                break;
            default:
                return QString ( RS_ELEMENT_TAG );
                break;
        }
    }

    RSInstanceType RSInstance::InstanceTagToType ( const QString& rTag )
    {

        if ( rTag == RS_ANIMATION_INSTANCE_TAG )
        {
            return RS_ANIMATION_INSTANCE;
        }
        else if ( rTag == RS_CAMERA_INSTANCE_TAG )
        {
            return RS_CAMERA_INSTANCE;
        }
        else if ( rTag == RS_CONTROLLER_INSTANCE_TAG )
        {
            return RS_CONTROLLER_INSTANCE;
        }
        else if ( rTag == RS_FORMULA_INSTANCE_TAG )
        {
            return RS_FORMULA_INSTANCE;
        }
        else if ( rTag == RS_GEOMETRY_INSTANCE_TAG )
        {
            return RS_GEOMETRY_INSTANCE;
        }
        else if ( rTag == RS_LIGHT_INSTANCE_TAG )
        {
            return RS_LIGHT_INSTANCE;
        }
        else if ( rTag == RS_NODE_INSTANCE_TAG )
        {
            return RS_NODE_INSTANCE;
        }
        else if ( rTag == RS_VISUAL_SCENE_INSTANCE_TAG )
        {
            return RS_VISUAL_SCENE_INSTANCE;
        }

        return RS_UNKNOWN_INSTANCE;
    }
}
